#!/usr/bin/python3
# -*- encoding: utf-8 -*-
'''
@File        :test.py
@Time        :2020/08/26 09:43:07
@Author      :hejiang
@Software    :vsCode
'''

from selenium import webdriver
import time

# chrome = webdriver.Chrome()

chrome = webdriver.Chrome(executable_path='D:\chrome\chromedriver.exe')
chrome.get("https://passport.bilibili.com/login")
#通过Xpath定位到“排行榜”的url://a[@target="_blank"][contains(text(),"排行榜")]/@href
#登录输入框的ID：login-username,login-passwd
chrome.find_element_by_id("login-username").send_keys("130xxxxx011")
chrome.find_element_by_id("login-passwd").send_keys("cpxxxxxx34")
time.sleep(2)
chrome.find_element_by_xpath('//a[text()="登录"]').click()
time.sleep(5)
chrome.find_element_by_xpath(
    '//a[@target="_blank"][contains(text(),"排行榜")]').click()
chrome.switch_to.window(chrome.window_handles[1])
print(chrome.current_url)
time.sleep(5)
print(chrome.current_url)
with open("first.html", "w", encoding="utf-8") as file:
    file.write(chrome.page_source)
chrome.quit()  #关闭当前页面
